package handler

import (
	"github.com/gin-gonic/gin"
	"myApp/service"
	"unicode/utf8"
)

func Get(c *gin.Context) {
	getReq := &service.GetServiceRequest{}
	if err := c.ShouldBindJSON(getReq); err != nil {
		c.JSON(400, gin.H{"error": err})
		return
	}
	if (len(getReq.CustId) == 0 && len(getReq.Mobile) == 0) || utf8.RuneCountInString(getReq.CustId) > 20 || utf8.RuneCountInString(getReq.Mobile) > 20 {
		c.JSON(400, gin.H{"error": "Invalid Params"})
		return
	}
	// 查询数据库
	getResp, err := service.GetService(getReq)
	if err != nil {
		c.JSON(400, gin.H{"error": err})
		return
	}
	c.JSON(200, getResp)
}

func Export(c *gin.Context) {
	expReq := &service.ExportServiceRequest{}
	err := c.Bind(expReq)
	if err != nil {
		return
	}
	c.JSON(200, expReq)
}
